{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据格式，csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pandas中的dataframe操作，和numpy的二维数组类似"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df =pd.read_csv(\"file/score.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>60</td>\n",
       "      <td>89</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>62</td>\n",
       "      <td>87</td>\n",
       "      <td>71</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>64</td>\n",
       "      <td>85</td>\n",
       "      <td>72</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>66</td>\n",
       "      <td>83</td>\n",
       "      <td>73</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>68</td>\n",
       "      <td>81</td>\n",
       "      <td>74</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>70</td>\n",
       "      <td>79</td>\n",
       "      <td>75</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>72</td>\n",
       "      <td>77</td>\n",
       "      <td>76</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>74</td>\n",
       "      <td>75</td>\n",
       "      <td>77</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>76</td>\n",
       "      <td>73</td>\n",
       "      <td>78</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>78</td>\n",
       "      <td>71</td>\n",
       "      <td>79</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>80</td>\n",
       "      <td>69</td>\n",
       "      <td>80</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>82</td>\n",
       "      <td>67</td>\n",
       "      <td>81</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>84</td>\n",
       "      <td>65</td>\n",
       "      <td>82</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>86</td>\n",
       "      <td>63</td>\n",
       "      <td>83</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>88</td>\n",
       "      <td>61</td>\n",
       "      <td>84</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>90</td>\n",
       "      <td>59</td>\n",
       "      <td>85</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>92</td>\n",
       "      <td>57</td>\n",
       "      <td>86</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>94</td>\n",
       "      <td>55</td>\n",
       "      <td>87</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>96</td>\n",
       "      <td>53</td>\n",
       "      <td>88</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>98</td>\n",
       "      <td>51</td>\n",
       "      <td>89</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id   name     sex  chinese  math  english  wuli  huaxue\n",
       "0    1   lily    male       60    89       70    29      12\n",
       "1    2   lucy  famale       62    87       71    28      23\n",
       "2    3  lilei    male       64    85       72    29      12\n",
       "3    4   lily  famale       66    83       73    28      23\n",
       "4    5   lucy    male       68    81       74    29      12\n",
       "5    6  lilei  famale       70    79       75    28      23\n",
       "6    7   lily    male       72    77       76    29      12\n",
       "7    8   lucy  famale       74    75       77    28      23\n",
       "8    9  lilei    male       76    73       78    29      12\n",
       "9   10   lily  famale       78    71       79    28      23\n",
       "10  11   lucy    male       80    69       80    29      12\n",
       "11  12  lilei  famale       82    67       81    28      23\n",
       "12  13   lily    male       84    65       82    29      12\n",
       "13  14   lucy  famale       86    63       83    28      23\n",
       "14  15  lilei    male       88    61       84    29      12\n",
       "15  16   lily  famale       90    59       85    28      23\n",
       "16  17   lucy    male       92    57       86    29      12\n",
       "17  18  lilei  famale       94    55       87    28      23\n",
       "18  19   lily    male       96    53       88    29      12\n",
       "19  20   lucy  famale       98    51       89    28      23"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>60</td>\n",
       "      <td>89</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>62</td>\n",
       "      <td>87</td>\n",
       "      <td>71</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id  name     sex  chinese  math  english  wuli  huaxue\n",
       "0   1  lily    male       60    89       70    29      12\n",
       "1   2  lucy  famale       62    87       71    28      23"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['id', 'name', 'sex', 'chinese', 'math', 'english', 'wuli', 'huaxue'], dtype='object')"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列名\n",
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=20, step=1)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 索引\n",
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=np.array(range(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False, False, False,  True,  True,  True,  True,  True,\n",
       "        True])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a>3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      True\n",
       "1      True\n",
       "2     False\n",
       "3     False\n",
       "4     False\n",
       "5     False\n",
       "6     False\n",
       "7     False\n",
       "8     False\n",
       "9     False\n",
       "10    False\n",
       "11    False\n",
       "12    False\n",
       "13    False\n",
       "14    False\n",
       "15    False\n",
       "16    False\n",
       "17    False\n",
       "18    False\n",
       "19    False\n",
       "Name: math, dtype: bool"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 筛选数学成绩大于85\n",
    "df.math>85"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df.math>85)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>60</td>\n",
       "      <td>89</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>62</td>\n",
       "      <td>87</td>\n",
       "      <td>71</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id  name     sex  chinese  math  english  wuli  huaxue\n",
       "0   1  lily    male       60    89       70    29      12\n",
       "1   2  lucy  famale       62    87       71    28      23"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 简单筛选\n",
    "df[df.math>85]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>72</td>\n",
       "      <td>77</td>\n",
       "      <td>76</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>74</td>\n",
       "      <td>75</td>\n",
       "      <td>77</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>76</td>\n",
       "      <td>73</td>\n",
       "      <td>78</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>78</td>\n",
       "      <td>71</td>\n",
       "      <td>79</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id   name     sex  chinese  math  english  wuli  huaxue\n",
       "6   7   lily    male       72    77       76    29      12\n",
       "7   8   lucy  famale       74    75       77    28      23\n",
       "8   9  lilei    male       76    73       78    29      12\n",
       "9  10   lily  famale       78    71       79    28      23"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 复杂筛选\n",
    "df[(df.chinese>70) & (df.math>70) & (df.english>70)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>98</td>\n",
       "      <td>51</td>\n",
       "      <td>89</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>96</td>\n",
       "      <td>53</td>\n",
       "      <td>88</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>94</td>\n",
       "      <td>55</td>\n",
       "      <td>87</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>92</td>\n",
       "      <td>57</td>\n",
       "      <td>86</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>90</td>\n",
       "      <td>59</td>\n",
       "      <td>85</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id   name     sex  chinese  math  english  wuli  huaxue\n",
       "19  20   lucy  famale       98    51       89    28      23\n",
       "18  19   lily    male       96    53       88    29      12\n",
       "17  18  lilei  famale       94    55       87    28      23\n",
       "16  17   lucy    male       92    57       86    29      12\n",
       "15  16   lily  famale       90    59       85    28      23"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values(['math','huaxue']).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 访问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>60</td>\n",
       "      <td>89</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>62</td>\n",
       "      <td>87</td>\n",
       "      <td>71</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>64</td>\n",
       "      <td>85</td>\n",
       "      <td>72</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>66</td>\n",
       "      <td>83</td>\n",
       "      <td>73</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>68</td>\n",
       "      <td>81</td>\n",
       "      <td>74</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>70</td>\n",
       "      <td>79</td>\n",
       "      <td>75</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>72</td>\n",
       "      <td>77</td>\n",
       "      <td>76</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>74</td>\n",
       "      <td>75</td>\n",
       "      <td>77</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>76</td>\n",
       "      <td>73</td>\n",
       "      <td>78</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>78</td>\n",
       "      <td>71</td>\n",
       "      <td>79</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>80</td>\n",
       "      <td>69</td>\n",
       "      <td>80</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>82</td>\n",
       "      <td>67</td>\n",
       "      <td>81</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>84</td>\n",
       "      <td>65</td>\n",
       "      <td>82</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>86</td>\n",
       "      <td>63</td>\n",
       "      <td>83</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>88</td>\n",
       "      <td>61</td>\n",
       "      <td>84</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>90</td>\n",
       "      <td>59</td>\n",
       "      <td>85</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>92</td>\n",
       "      <td>57</td>\n",
       "      <td>86</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>94</td>\n",
       "      <td>55</td>\n",
       "      <td>87</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>96</td>\n",
       "      <td>53</td>\n",
       "      <td>88</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>98</td>\n",
       "      <td>51</td>\n",
       "      <td>89</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id   name     sex  chinese  math  english  wuli  huaxue\n",
       "0    1   lily    male       60    89       70    29      12\n",
       "1    2   lucy  famale       62    87       71    28      23\n",
       "2    3  lilei    male       64    85       72    29      12\n",
       "3    4   lily  famale       66    83       73    28      23\n",
       "4    5   lucy    male       68    81       74    29      12\n",
       "5    6  lilei  famale       70    79       75    28      23\n",
       "6    7   lily    male       72    77       76    29      12\n",
       "7    8   lucy  famale       74    75       77    28      23\n",
       "8    9  lilei    male       76    73       78    29      12\n",
       "9   10   lily  famale       78    71       79    28      23\n",
       "10  11   lucy    male       80    69       80    29      12\n",
       "11  12  lilei  famale       82    67       81    28      23\n",
       "12  13   lily    male       84    65       82    29      12\n",
       "13  14   lucy  famale       86    63       83    28      23\n",
       "14  15  lilei    male       88    61       84    29      12\n",
       "15  16   lily  famale       90    59       85    28      23\n",
       "16  17   lucy    male       92    57       86    29      12\n",
       "17  18  lilei  famale       94    55       87    28      23\n",
       "18  19   lily    male       96    53       88    29      12\n",
       "19  20   lucy  famale       98    51       89    28      23"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "id              2\n",
       "name         lucy\n",
       "sex        famale\n",
       "chinese        62\n",
       "math           87\n",
       "english        71\n",
       "wuli           28\n",
       "huaxue         23\n",
       "Name: 1, dtype: object"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "scores={\n",
    "    'english':[90,78,89],\n",
    "    'math':[64,78,45],\n",
    "    'name':['lily','lucy','lilei']\n",
    "}\n",
    "df1=pd.DataFrame(scores,index=['one','two','three'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>english</th>\n",
       "      <th>math</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>one</th>\n",
       "      <td>90</td>\n",
       "      <td>64</td>\n",
       "      <td>lily</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>78</td>\n",
       "      <td>78</td>\n",
       "      <td>lucy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>three</th>\n",
       "      <td>89</td>\n",
       "      <td>45</td>\n",
       "      <td>lilei</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       english  math   name\n",
       "one         90    64   lily\n",
       "two         78    78   lucy\n",
       "three       89    45  lilei"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['one', 'two', 'three'], dtype='object')"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "english      90\n",
       "math         64\n",
       "name       lily\n",
       "Name: one, dtype: object"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 不能通过数字索引去访问\n",
    "#df1.loc[1]\n",
    "df1.loc['one']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "english      90\n",
       "math         64\n",
       "name       lily\n",
       "Name: one, dtype: object"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 真正的行数，注意iloc和loc的区别\n",
    "df1.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.6/site-packages/ipykernel_launcher.py:1: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "english      90\n",
       "math         64\n",
       "name       lily\n",
       "Name: one, dtype: object"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.ix[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>english</th>\n",
       "      <th>math</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>one</th>\n",
       "      <td>90</td>\n",
       "      <td>64</td>\n",
       "      <td>lily</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>78</td>\n",
       "      <td>78</td>\n",
       "      <td>lucy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     english  math  name\n",
       "one       90    64  lily\n",
       "two       78    78  lucy"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.iloc[:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>english</th>\n",
       "      <th>math</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>one</th>\n",
       "      <td>90</td>\n",
       "      <td>64</td>\n",
       "      <td>lily</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>78</td>\n",
       "      <td>78</td>\n",
       "      <td>lucy</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     english  math  name\n",
       "one       90    64  lily\n",
       "two       78    78  lucy"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 访问某一行，是错误的\n",
    "# df1[0]\n",
    "# 访问多行，可以使用切片\n",
    "df1[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[90, 64, 'lily'],\n",
       "       [78, 78, 'lucy'],\n",
       "       [89, 45, 'lilei']], dtype=object)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([64, 78, 45])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dataframe中的数组\n",
    "df1.math.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "78    1\n",
       "45    1\n",
       "64    1\n",
       "Name: math, dtype: int64"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 简单的统计\n",
    "df1.math.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "one      64\n",
       "two      78\n",
       "three    45\n",
       "Name: math, dtype: int64"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>math</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>one</th>\n",
       "      <td>lily</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>two</th>\n",
       "      <td>lucy</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>three</th>\n",
       "      <td>lilei</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name  math\n",
       "one     lily    64\n",
       "two     lucy    78\n",
       "three  lilei    45"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 提取多列\n",
    "df1[['name','math']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "new =df[['math','chinese']].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>math</th>\n",
       "      <th>chinese</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>89</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>87</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>85</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>83</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>81</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   math  chinese\n",
       "0    89       60\n",
       "1    87       62\n",
       "2    85       64\n",
       "3    83       66\n",
       "4    81       68"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>math</th>\n",
       "      <th>chinese</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>178</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>174</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>170</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>166</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>162</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   math  chinese\n",
       "0   178      120\n",
       "1   174      124\n",
       "2   170      128\n",
       "3   166      132\n",
       "4   162      136"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(score):\n",
    "    if score>=80:\n",
    "        return 'best'\n",
    "    elif score>=70:\n",
    "        return 'good'\n",
    "    elif score>=60:\n",
    "        return 'ok'\n",
    "    else:\n",
    "        return 'bad'\n",
    "# map对单行数据进行操作\n",
    "df['mathtype']=df.math.map(func)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "      <th>mathtype</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>60</td>\n",
       "      <td>89</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>62</td>\n",
       "      <td>87</td>\n",
       "      <td>71</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>64</td>\n",
       "      <td>85</td>\n",
       "      <td>72</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>66</td>\n",
       "      <td>83</td>\n",
       "      <td>73</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>68</td>\n",
       "      <td>81</td>\n",
       "      <td>74</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>70</td>\n",
       "      <td>79</td>\n",
       "      <td>75</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>good</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>72</td>\n",
       "      <td>77</td>\n",
       "      <td>76</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>good</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>74</td>\n",
       "      <td>75</td>\n",
       "      <td>77</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>good</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>76</td>\n",
       "      <td>73</td>\n",
       "      <td>78</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>good</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>78</td>\n",
       "      <td>71</td>\n",
       "      <td>79</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>good</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>80</td>\n",
       "      <td>69</td>\n",
       "      <td>80</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>ok</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>82</td>\n",
       "      <td>67</td>\n",
       "      <td>81</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>ok</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>84</td>\n",
       "      <td>65</td>\n",
       "      <td>82</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>ok</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>86</td>\n",
       "      <td>63</td>\n",
       "      <td>83</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>ok</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>88</td>\n",
       "      <td>61</td>\n",
       "      <td>84</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>ok</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>90</td>\n",
       "      <td>59</td>\n",
       "      <td>85</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>92</td>\n",
       "      <td>57</td>\n",
       "      <td>86</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>lilei</td>\n",
       "      <td>famale</td>\n",
       "      <td>94</td>\n",
       "      <td>55</td>\n",
       "      <td>87</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>96</td>\n",
       "      <td>53</td>\n",
       "      <td>88</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>98</td>\n",
       "      <td>51</td>\n",
       "      <td>89</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>bad</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id   name     sex  chinese  math  english  wuli  huaxue mathtype\n",
       "0    1   lily    male       60    89       70    29      12     best\n",
       "1    2   lucy  famale       62    87       71    28      23     best\n",
       "2    3  lilei    male       64    85       72    29      12     best\n",
       "3    4   lily  famale       66    83       73    28      23     best\n",
       "4    5   lucy    male       68    81       74    29      12     best\n",
       "5    6  lilei  famale       70    79       75    28      23     good\n",
       "6    7   lily    male       72    77       76    29      12     good\n",
       "7    8   lucy  famale       74    75       77    28      23     good\n",
       "8    9  lilei    male       76    73       78    29      12     good\n",
       "9   10   lily  famale       78    71       79    28      23     good\n",
       "10  11   lucy    male       80    69       80    29      12       ok\n",
       "11  12  lilei  famale       82    67       81    28      23       ok\n",
       "12  13   lily    male       84    65       82    29      12       ok\n",
       "13  14   lucy  famale       86    63       83    28      23       ok\n",
       "14  15  lilei    male       88    61       84    29      12       ok\n",
       "15  16   lily  famale       90    59       85    28      23      bad\n",
       "16  17   lucy    male       92    57       86    29      12      bad\n",
       "17  18  lilei  famale       94    55       87    28      23      bad\n",
       "18  19   lily    male       96    53       88    29      12      bad\n",
       "19  20   lucy  famale       98    51       89    28      23      bad"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "      <th>mathtype</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1-</td>\n",
       "      <td>lily-</td>\n",
       "      <td>male-</td>\n",
       "      <td>60-</td>\n",
       "      <td>89-</td>\n",
       "      <td>70-</td>\n",
       "      <td>29-</td>\n",
       "      <td>12-</td>\n",
       "      <td>best-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2-</td>\n",
       "      <td>lucy-</td>\n",
       "      <td>famale-</td>\n",
       "      <td>62-</td>\n",
       "      <td>87-</td>\n",
       "      <td>71-</td>\n",
       "      <td>28-</td>\n",
       "      <td>23-</td>\n",
       "      <td>best-</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id   name      sex chinese math english wuli huaxue mathtype\n",
       "0  1-  lily-    male-     60-  89-     70-  29-    12-    best-\n",
       "1  2-  lucy-  famale-     62-  87-     71-  28-    23-    best-"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对所有的数据进行操作的函数\n",
    "df.applymap(lambda x: str(x)+'-').head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "      <th>mathtype</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>60</td>\n",
       "      <td>89</td>\n",
       "      <td>70</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>62</td>\n",
       "      <td>87</td>\n",
       "      <td>71</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>lilei</td>\n",
       "      <td>male</td>\n",
       "      <td>64</td>\n",
       "      <td>85</td>\n",
       "      <td>72</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>lily</td>\n",
       "      <td>famale</td>\n",
       "      <td>66</td>\n",
       "      <td>83</td>\n",
       "      <td>73</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>lucy</td>\n",
       "      <td>male</td>\n",
       "      <td>68</td>\n",
       "      <td>81</td>\n",
       "      <td>74</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>best</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id   name     sex  chinese  math  english  wuli  huaxue mathtype\n",
       "0   1   lily    male       60    89       70    29      12     best\n",
       "1   2   lucy  famale       62    87       71    28      23     best\n",
       "2   3  lilei    male       64    85       72    29      12     best\n",
       "3   4   lily  famale       66    83       73    28      23     best\n",
       "4   5   lucy    male       68    81       74    29      12     best"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     89\n",
       "1     87\n",
       "2     85\n",
       "3     83\n",
       "4     81\n",
       "5     79\n",
       "6     77\n",
       "7     75\n",
       "8     73\n",
       "9     71\n",
       "10    69\n",
       "11    67\n",
       "12    65\n",
       "13    63\n",
       "14    61\n",
       "15    59\n",
       "16    57\n",
       "17    55\n",
       "18    53\n",
       "19    51\n",
       "dtype: int64"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 匿名函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[100, 101, 102, 103, 104, 105, 106, 107, 108, 109]"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[i+100 for i in range(10)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#def func(x):\n",
    "#    return x+100\n",
    "\n",
    "# 等价\n",
    "#func=lambda number: number+100\n",
    "\n",
    "list(map(func,range(10)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[100, 101, 102, 103, 104, 105, 106, 107, 108, 109]"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(lambda x:x+100,range(10)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "#生成新的一列\n",
    "df['sum_score']=df.apply(lambda x:x.math+x.chinese,axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>chinese</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>wuli</th>\n",
       "      <th>huaxue</th>\n",
       "      <th>mathtype</th>\n",
       "      <th>sum_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>lily</td>\n",
       "      <td>male</td>\n",
       "      <td>96</td>\n",
       "      <td>53</td>\n",
       "      <td>88</td>\n",
       "      <td>29</td>\n",
       "      <td>12</td>\n",
       "      <td>bad</td>\n",
       "      <td>149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>lucy</td>\n",
       "      <td>famale</td>\n",
       "      <td>98</td>\n",
       "      <td>51</td>\n",
       "      <td>89</td>\n",
       "      <td>28</td>\n",
       "      <td>23</td>\n",
       "      <td>bad</td>\n",
       "      <td>149</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    id  name     sex  chinese  math  english  wuli  huaxue mathtype  sum_score\n",
       "18  19  lily    male       96    53       88    29      12      bad        149\n",
       "19  20  lucy  famale       98    51       89    28      23      bad        149"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
